package webdriver;

import org.openqa.selenium.By;

/**
 * Base form
 */
public abstract class BaseForm extends BaseEntity {

	private static final String CREATE_SCREEN_EVERY_STEP = "org.uncommons.reportng.everystepscreen";
	/**
	 * @uml.property name="titleLocator"
	 * @uml.associationEnd multiplicity="(1 1)"
	 */
	protected By titleLocator; // detect form opening locator
	/**
	 * @uml.property name="title"
	 */
	protected String title; // title of a form
	/**
	 * @uml.property name="name"
	 */
	protected String name; // full name of form that outputted to log, for example, "Form 'Login'"

	/**
	 * Contructor
	 * @param locator Locator
	 * @param formTitle Name
	 */
	protected BaseForm(final By locator, final String formTitle) {
		init(locator, formTitle);
	}

	/**
	 * Contructor #2
	 * @param locator Locator
	 * @param formTitle Name
	 */
	protected BaseForm(String xpathLocatorTemplate, String locatorValue, String formTitle) {
		init(By.xpath(String.format(xpathLocatorTemplate, locatorValue)), formTitle);
	}
	
	/**
	 * For logs
	 * @param message Message
	 * @return Message
	 */
	protected String formatLogMsg(final String message) {
		return message;
	}

    /**
     * In report: If "true": when opening page screenshot is taken
     * @return boolean
     */
    public boolean shouldCreateScreenEveryStep(){
        return System.getProperty(CREATE_SCREEN_EVERY_STEP, "false").equalsIgnoreCase("true");
    }

	/**
	 * Init
	 * @param locator Locator
	 * @param formTitle Name
	 */
	private void init(final By locator, final String formTitle) {
		titleLocator = locator;
		title = formTitle;
		name = String.format(getLoc("loc.form") + " '%1$s'", this.title);
	}
}
